import time,pymysql

from PIL import Image
# from data import db
from selenium import webdriver
from selenium.webdriver.common.by import By

from unit820.dama import Dama
# sql = db('root','yidong666','10.59.9.12','a3mall')

# A3mall 登陆页面 自动输入验证码  截取验证码图片

driver=webdriver.Edge()
driver.get('http://10.59.9.12:7001/')
driver.maximize_window()
time.sleep(3)

driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
time.sleep(3)
driver.find_element(By.NAME,'username').send_keys('13811033962')
time.sleep(3)
driver.find_element(By.NAME,'password').send_keys('123456')
time.sleep(10)
# ye = sql.select('select amount from mall_users where username = "13811033962"')
# print(ye[0][0])
driver.find_element(By.XPATH,'//*[@id="theForm"]/div[5]/a').click()
time.sleep(5)
driver.switch_to.window(driver.window_handles[-1])
time.sleep(2)

datu=driver.save_screenshot('datu.png')
yzmtu=driver.find_element(By.XPATH,'//*[@id="theForm"]/div[3]/span[3]/img')
# 位置
location = yzmtu.location
print(location)
# 大小
size = yzmtu.size
print(size)


left=location['x']
top=location['y']
right=left+size['width']
bottom=top+size['height']
image=Image.open('datu.png')
imagex=image.crop((left*2,top*2,right*2,bottom*2))
imagex.save('imageyzm.png')

da=Dama('13103053968aaa','kev304ep','972467')
yzmda=open('imageyzm.png','rb').read()
jieguo=da.PostPic(yzmda,'1902')
print(jieguo)
result=jieguo['pic_str']
time.sleep(3)
driver.find_element(By.XPATH,'//*[@id="theForm"]/div[3]/span[2]/input').send_keys(result)
driver.find_element(By.CLASS_NAME,'finish-btn').click()
time.sleep(5)






# dy3=driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span').text
# print(dy3.replace('¥ ',''))
#
# db().select('FLUSH TABLES')
#
#
# assert float(dy3.replace('¥ ',''))==float(ye[0][0])